package netty.protocoltcp;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @ClassName MyMessageEncoder
 * @Description TODO
 * @Author director吴
 * @Date 2022/5/17 17:01
 * @Version 1.0
 **/
public class MyMessageEncoder extends MessageToByteEncoder<MessageProtocol> {

    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, MessageProtocol msg, ByteBuf byteBuf) throws Exception {


        System.out.println("MyMessageEncoder--encode（）方法被调用");


        byteBuf.writeInt(msg.getLenth());
        byteBuf.writeBytes(msg.getCount());


    }





}
